package com.woniuxy.thread.job;

//code review 代码评审
/**
 * 1,写两个线程，一个线程打印1-52，另一个线程打印A-Z(65-91)，打印顺序是12A34B...5152Z
 *
 * @author 老谭 (<a href="http://www.woniuxy.com">蜗牛学苑</a>)
 *
 */
public class Resource {
	private boolean flag = false;
	private int num = 1;
	private char c = 'A';

	/**
	 * 打印数字
	 * 
	 * @throws Exception
	 */
	public synchronized void printDigit() throws Exception {
		while (flag) {
			wait();
		}
		System.out.print(num + "" + ++num);
		num++;
		flag = !flag;
		notifyAll();
	}

	/**
	 * 打印字母
	 * 
	 * @throws Exception
	 */
	public synchronized void printLetter() throws Exception {
		while (!flag) {
			wait();
		}
		System.out.print(c++);
		flag = !flag;
		notifyAll();
	}

}
